// pages/doctor-my-rz/doctor-my-rz.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    doctorId: "", //医生ID
    zhengshu: [],
    myHeadImg: '', //本地的头像url
    userInfo: {}, //获取微信的 头像，昵称，性别
    honorImg: '', //图片路径
    honorDesc: '', //荣誉证书说明
    honorId: '', //医生荣誉证书ID
    hasUserInfo: false,
    file: '', //文件
    tupian: "",
    imageone: "",
    imagetwo: "",
    credentialone: "荣誉证书",
    credentialtwo: "荣誉证书",
    imgUrl: app.globalData.imgUrl, //请求接口图片路径
    localImg: app.globalData.staticimgUrl,  // 本地图片
  },
  // 上传荣誉证书1图片
  updateone: function(e) {
    var that = this;
    var credential = that.data.credentialone;
    var imgId = e; 
    
    wx.chooseImage({
      count: 1,
      sizeType: ["original", "compressed"],
      sourceType: ["album", "camera"],
      success: function(e) {
        console.log(e);
        var a = e.tempFilePaths[0];
        console.log('ceshi', a);
        app.uploadFile({
          url: 'doctor/doctor/uploadCertFile',
          filePath: a,
          success: function(res) {
            var path = JSON.parse(res.data).data[0].filePath;
            that.setData({
              imageone: path
            });
            
            app.request({
              url: 'doctor/doctor/saveHonor',
              data: {
                'honorImg': path,
                'honorDesc': credential
              },
              success(res) {
                that.del(imgId);
                that.onLoad();
              }
            })
          },
          fail: function(e) {
            console.log(e)
          }
        })
      }
    })
  },
  // 上传荣誉证书2图片
  updatetwo: function() {
    var that = this;
    var credential = that.data.credentialtwo;
    wx.chooseImage({
      count: 1,
      sizeType: ["original", "compressed"],
      sourceType: ["album", "camera"],
      success: function(e) {
        var a = e.tempFilePaths[0];
      
        app.uploadFile({
          url: 'doctor/doctor/uploadCertFile',
          filePath: a,
          success: function(res) {
            var path = JSON.parse(res.data).data[0].filePath;
            that.setData({
              imagetwo: path
            })
            app.request({
              url: 'doctor/doctor/saveHonor',
              data: {
                'honorImg': path,
                'honorDesc': credential
              },
              success(res) {
                that.onLoad(wx.getStorageSync('userid'));
              }
            })
          },
          fail: function(e) {
            console.log(e)
          }
        })
      }
    })
  },
  //删除荣誉证书
  del: function(e) {
    var that = this;
    var id = e.currentTarget.dataset.imgid;
    // 美丽大片播放
    app.request({
      url: '/doctor/doctor/deleteHonor',
      data: {
        honorId: id
      },
      success: function(res) {
        that.getPageData();
      }
    })
  },

  getPageData:function(){
    var that = this;
    app.request({
      url: '/doctor/doctor/getHonor',
      data: {
        doctorId: wx.getStorageSync('userid'),
      },
      success: function (res) {
        that.setData({
          'zhengshu': res.data,
        });
      }
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.setData({
      url: app.globalData.imgUrl
    })
    this.getPageData();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})